package com.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.dao.CustomerDao;
import com.dao.TransferRecdDao;
import com.model.Group;
import com.model.ReponseDto;
import com.model.Statistics;
import com.service.IHomeService;

@Service
public class HomeServiceImpl implements IHomeService {

    @Autowired
    private TransferRecdDao transferRecdDao;

    @Autowired
    private CustomerDao customerDao;

    @Override
    public ReponseDto<Statistics> index() {
        Statistics s = new Statistics();
        s.setRegistered(customerDao.getTodayCount());
        List<Group> glist = transferRecdDao.getTodaySum();
        if (!CollectionUtils.isEmpty(glist)) {
            for (Group g : glist) {
                // 0收入，1支出，2冻结，3解冻
                if (StringUtils.equals("0", g.getKey())) {
                    s.setDeposit(g.getSum());
                } else if (StringUtils.equals("1", g.getKey())) {
                    s.setWithdraw(g.getSum());
                }
            }

        }
        List<Group> rlist = transferRecdDao.getReview();
        if (!CollectionUtils.isEmpty(rlist)) {

            for (Group r : rlist) {
                // 状态，0 待处理，1成功，2失败,3 审核成功， 4审核失败
                if (StringUtils.equals("0", r.getKey())) {
                    s.setReview(r.getSum());
                }
            }

        }
        return new ReponseDto<>(s);
    }

}
